package com.alen.sun.controller;

import com.alen.sun.bean.Content;
import com.alen.sun.bean.Result;
import com.alen.sun.service.ContentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin
@RequestMapping("/contents")
@RestController
public class ContentController {

    @Autowired
    private ContentService contentService;

    /**
     * 获取按钮内容
     * @return
     */
    @GetMapping
    public Result list(){
        List<Content> contents = contentService.list();
        return Result.success(contents);
    }

    /**
     * 添加按键内容
     * @param content
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Content content){
        contentService.add(content);
        return Result.success();
    }

    @DeleteMapping("/id")
    public Result delete(@PathVariable Integer id){
        contentService.delete(id);
        return Result.success();
    }


    @GetMapping("/id")
    public Result getById(@PathVariable Integer id){
        Content content=contentService.getById(id);
        return Result.success(content);
    }

    @PutMapping
    public Result update(@RequestBody Content content){
        contentService.update(content);
        return Result.success();
    }

    @DeleteMapping("/ids")
    @ResponseBody
    public Result deletes(@RequestBody List<Integer> ids){
        contentService.deletes(ids);
        return Result.success();
    }

//    @GetMapping
//    public Result getByWord(String word){
//
//    }
}
